<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function checkAdd(){
	var sid = document.getElementById("i1").value;
	var sname = document.getElementById("i2").value;
	var sage = document.getElementById("i3").value;
	var sdate= document.getElementById("i4").value;
	if(sid== ""){ 
		document.getElementById("s1").innerHTML="<font color='red'>亲，学号不能为空</font>";
		return false;
	}else if(sname== ""){
		document.getElementById("s2").innerHTML="<font color='red'>亲，姓名不能为空</font>";
		return false;
	}else if(sage== ""){
		document.getElementById("s3").innerHTML="<font color='red'>亲，年龄不能为空</font>";
		return false;
	}else if(sdate== ""){
		document.getElementById("s4").innerHTML="<font color='red'>亲，入学日期不能为空</font>";
		return false;
	}else{
		return true;
	} 
	
}

function checkDate() {
	var date=document.getElementById("i4").value;
	//定义正则表达式
	//方法一:直接以字面量的方式定义正则表达式
	var reg=/\d{4}-\d{2}-\d{2}/;
	//方法二：var reg=new RegExp("正则表达式");
	if(reg.test(date)==false){//使用正则对象中的test方法来验证用户内容是否匹配
		alert("亲，日期格式不正确(⊙o⊙)哦");
	}
	
}
</script>
</head>
<body>
	<form action="../addStu" method="post" onsubmit="return checkAdd()">
		<table>
			<tr>
				<td>学生编号:<input type="text" name="sid" id="i1"><span id="s1"></span></td>
				
			</tr>
			<tr>
				<td>学生姓名:<input type="text" name="sname" id="i2"><span id="s2"></span></td>
				
			</tr>
			<tr>
				<td>学生年龄:<input type="text" name="sage" id="i3"><span id="s3"></span></td>
				
			</tr>
			<tr>
				<td>入学日期:<input type="text" name="sdate" id="i4" onblur="checkDate()"><span id="s4"></span></td>
				
			</tr>
			<tr>
				<td style="float: left"><input type="submit" value="确定" ></td>
				<td style="float: left"><input type="reset" value="重置" ></td>
			</tr>
		</table>
	</form>
</body>
</html>